<template>
	<view class="link-view">
		 <view class="list-parent">
			 <view v-if="userPQD" class="list-item"  v-for="(item , index) in list" :key="'item'+index">
					<view class="list-item-title-view">
						<image v-if="!item.isOpen" class="title-arrow" src="../../static/right-shixin-arrow.png" mode="scaleToFill"></image>
						<image v-if="item.isOpen" class="title-arrow" src="../../static/down-shixin-arrow.png" mode="scaleToFill"></image>
						<text class="title-txt" v-if="item.type=='1'" style="padding-left: 2rpx;" @click="itemClick" :data-index="item">{{item.title}}</text>
						<text class="title-txt" v-else-if="item.type=='2'" style="padding-left: 18rpx;" @click="itemClick" :data-index="item">{{item.title}}</text>
						<text class="title-txt" v-else style="padding-left: 15rpx;" @click="itemClick" :data-index="item">{{item.title}}</text>
						<text class="title-member-count">{{item.info.length}}</text>
					</view>
					<view style="width: 100%;height: 2rpx;background-color: #F5F6FA;"></view>
					<view v-if="item.isOpen" class="list-inner-item"  v-for="(innerItem , innerIndex) in item.info"
					:key="'item-inner-'+innerIndex" @click="itemInnerClick" :data-index="innerItem">
						<image class="list-inner-item-image" :src="innerItem.avatar"></image>
						<view class="list-inner-item-content-view">
							<text class="list-inner-item-content-name">{{innerItem.name}}</text>
							<text class="list-inner-item-content-phone">{{innerItem.mobile}}</text>
						</view>
					</view>
			 </view>
		 </view>
		 <LoginTipDialog :isShow="isShowLoginTip" dataSource="登录查看具体信息"  @returnLoginTipDialog="returnLoginTipDialog"/>
	</view>
</template>

<script>
	import request from '../index/request.js';
	import LoginTipDialog from "@/components/login-tip-dialog/login-tip-dialog.vue";
	export default {
		components: {
			LoginTipDialog
		},
		data() {
			return {
				list:[
					
				],
				userPQD:"",
				isShowLoginTip:false,
			}
		},
		methods: {
			returnLoginTipDialog:function(e){
				this.isShowLoginTip=e.isclose
				if(e.tag){
					uni.navigateTo({
						url:"../index/index"
					})
				}
			},
			onLoad:function(options){
				this.appUtil.saveAppInviteId(options)
			},
			onShow:function(){
				var that=this
				var user = uni.getStorageSync("shiqin-user")
				this.share.url='/pages/tabBar/home/index?appInviteId='+this.appUtil.getAppInviteId()
				this.share.shareType=1
				this.userPQD=user.PQD
				if(user.PQD){
					this.GetTreeBindingMember()
				}else{
					this.isShowLoginTip=true
				}
			},
			GetTreeBindingMember:function(){
				var that=this
				request.post("api/apiv2/GetTreeBindingMember",{
				}).then(data=>{
					that.list=data
					for (var i = 0; i < that.list.length; i++) {
						that.list[i].isOpen=false
					}
				})
			},
			itemClick:function(e){
				let item = e.currentTarget.dataset.index;
				let list = JSON.parse(JSON.stringify(this.list));
				list.forEach((elem,ind)=>{
					if(elem.title===item.title){
						if(elem.isOpen){
							elem.isOpen= false
						}else{
							elem.isOpen= true
						}
					}
				})
				this.list  =  list
			},
			itemInnerClick:function(e){
				let item = e.currentTarget.dataset.index;
				uni.makePhoneCall({
				 	// 手机号
				    phoneNumber: item.mobile, 
					// 成功回调
					success: (res) => {
						console.log('调用成功!')	
					},
					// 失败回调
					fail: (res) => {
						console.log('调用失败!')
					}
				  });
			}
		}
	}
</script>

<style>
	@import "index.css";
</style>
